﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    internal class SetTimeoutCommand : ICommand
    {
        #region Constants

        private const int TimeoutArgIndex = 0;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            int result;

            if (false == int.TryParse((args.ElementAtOrDefault(TimeoutArgIndex) ?? string.Empty).ToString(), out result))
            {
                throw new ArgumentNullException((TimeoutArgIndex + 1).ToString() + ":TimeoutSeconds");
            }
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            harness.TimeoutSeconds = int.Parse((args.ElementAtOrDefault(TimeoutArgIndex) ?? string.Empty).ToString());

            return null;
        }
        
        #endregion
    }
}
